package com.risk.web.controller.ds;

import com.alibaba.fastjson2.JSONObject;
import com.risk.common.core.controller.BaseController;
import com.risk.common.core.domain.AjaxResult;
import com.risk.common.core.page.TableDataInfo;
import com.risk.common.utils.StringUtils;
import com.risk.kernel.domain.DsTripartiteAgreement;
import com.risk.kernel.service.IDsTripartiteAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2024/12/1
 * @description:
 */
@RestController
@RequestMapping("/ds/agreement")
public class DsTripartiteAgreementController extends BaseController {
    @Autowired
    private IDsTripartiteAgreementService dsTripartiteAgreementService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('ds:agreement:list')")
    @GetMapping("/list")
    public TableDataInfo list(String searchValue) {
        startPage();
        List<DsTripartiteAgreement> list = dsTripartiteAgreementService.selectDsTripartiteAgreementList(searchValue);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('ds:agreement:add')")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody DsTripartiteAgreement dsTripartiteAgreement) {
        String userName = StringUtils.isEmpty(getNickName()) ? getUsername() : getNickName();
        dsTripartiteAgreement.setCreateBy(userName);
        return toAjax(dsTripartiteAgreementService.insertDsTripartiteAgreement(dsTripartiteAgreement));
    }


    /**
     * 获取
     */
    @PreAuthorize("@ss.hasPermi('ds:agreement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(dsTripartiteAgreementService.selectDsTripartiteAgreementById(id));
    }


    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('ds:agreement:edit')")
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody DsTripartiteAgreement dsTripartiteAgreement) {
        return toAjax(dsTripartiteAgreementService.updateDsTripartiteAgreement(dsTripartiteAgreement));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('ds:agreement:remove')")
    @DeleteMapping("/bathRemove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(dsTripartiteAgreementService.deleteDsTripartiteAgreementByIds(ids));
    }

    /**
     * 查询网关所有的serviceCode
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('ds:agreement:serviceCode:list')")
    @GetMapping(value = "/serviceCode/catch/list")
    public TableDataInfo getServiceCodeList(String serviceCode) {
        startPage();
        return getDataTable(dsTripartiteAgreementService.getServiceCodeList(serviceCode));
    }


    @PreAuthorize("@ss.hasPermi('ds:agreement:serviceCode:catch')")
    @PostMapping(value = "/save/serviceCode/catch")
    public AjaxResult saveServiceCodeCatch(@RequestBody JSONObject jsonObject) {
        int i = dsTripartiteAgreementService.saveServiceCodeCatch(jsonObject);
        return toAjax(i);
    }

    @PreAuthorize("@ss.hasPermi('ds:agreement:thread:unlock:save')")
    @GetMapping(value = "save/thread/unlock")
    public AjaxResult saveThreadUnlock(boolean lock) {
        boolean b = dsTripartiteAgreementService.saveThreadUnlock(lock);
        return success(b);
    }

    @PreAuthorize("@ss.hasPermi('ds:agreement:thread:unlock:get')")
    @GetMapping(value = "/get/thread/unlock")
    public AjaxResult getThreadUnlock() {
        boolean b = dsTripartiteAgreementService.getThreadUnlock();
        return success(b);
    }
}
